package rs.etf.es.algorithm;

import java.util.Stack;

import javax.swing.JTextArea;

public class JTextAreaLogger implements ILogger {

    private JTextArea placeToLog;
    private Priority currentLevel;

    private static JTextAreaLogger statLogger;

    public static JTextAreaLogger instance() {
	if (statLogger == null) {
	    statLogger = new JTextAreaLogger();
	}

	return statLogger;

    }

    private Stack<String> logModel;

    private JTextAreaLogger() {
	logModel = new Stack<String>();
    }

    @Override
    public void log(String text) {
	if (placeToLog != null) {
	    if (placeToLog.getText() != "") {
		placeToLog.append("\n");
		logModel.push(text);
	    }

	    placeToLog.append(text);
	} else {
	    System.out.println(text);
	}
    }

    public Priority getCurrentLevel() {
	return currentLevel;
    }

    public void setCurrentLevel(Priority currentLevel) {
	this.currentLevel = currentLevel;
    }

    public void setPlaceToLog(JTextArea placeToLog) {
	this.placeToLog = placeToLog;
    }

    public String getCurrentText() {
	return placeToLog.getText();
    }

    @Override
    public void wakeUp() {
    }

    public void setCurrentText(String string) {
	placeToLog.setText(string);
    }

}
